package com.cskaoyan.service.index;

import com.cskaoyan.mapper.GoodsMapper;
import com.cskaoyan.mapper.GoodsProductMapper;
import com.cskaoyan.mapper.OrderMapper;
import com.cskaoyan.mapper.UserMapper;
import com.cskaoyan.model.bean.GoodsExample;
import com.cskaoyan.model.bean.GoodsProductExample;
import com.cskaoyan.model.bean.OrderExample;
import com.cskaoyan.model.bean.UserExample;
import com.cskaoyan.model.vo.IndexAllInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    UserMapper userMapper;
    @Autowired
    GoodsMapper goodsMapper;
    @Autowired
    GoodsProductMapper goodsProductMapper;
    @Autowired
    OrderMapper orderMapper;

    @Override
    public IndexAllInfoVo getIndexAllInfo() {
        //查询 user
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        criteria.andIdIsNotNull();
        long userCount = userMapper.countByExample(userExample);
        //查询 goods
        GoodsExample goodsExample = new GoodsExample();
        GoodsExample.Criteria goodsExampleCriteria = goodsExample.createCriteria();
        goodsExampleCriteria.andIdIsNotNull();
        long goodsCount = goodsMapper.countByExample(goodsExample);
        //查询 goodsProduct
        GoodsProductExample goodsProductExample = new GoodsProductExample();
        GoodsProductExample.Criteria goodsProductExampleCriteria = goodsProductExample.createCriteria();
        goodsProductExampleCriteria.andIdIsNotNull();
        long productCount = goodsProductMapper.countByExample(goodsProductExample);
        //查询 order
        OrderExample orderExample = new OrderExample();
        OrderExample.Criteria orderExampleCriteria = orderExample.createCriteria();
        orderExampleCriteria.andIdIsNotNull();
        long orderCount = orderMapper.countByExample(orderExample);

        //封装进Vo
        IndexAllInfoVo indexAllInfoVo = new IndexAllInfoVo();
        indexAllInfoVo.setUserTotal(userCount);
        indexAllInfoVo.setGoodsTotal(goodsCount);
        indexAllInfoVo.setProductTotal(productCount);
        indexAllInfoVo.setOrderTotal(orderCount);

        return indexAllInfoVo;
    }
}
